package com.ruoyi.crm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.crm.domain.CrmFeeApply;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.domain.CrmContract;
import com.ruoyi.crm.service.ICrmContractService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同数据Controller
 *
 * @author yanwenliang
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/crm/contract")
public class CrmContractController extends BaseController
{
    @Autowired
    private ICrmContractService crmContractService;

    /**
     * 查询合同数据列表
     */
//    @PreAuthorize("@ss.hasPermi('crm:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmContract crmContract)
    {
        startPage();
        List<CrmContract> list = crmContractService.selectCrmContractList(crmContract);
        return getDataTable(list);
    }

    /**
     * 导出合同数据列表
     */
//    @PreAuthorize("@ss.hasPermi('crm:contract:export')")
    @Log(title = "合同数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmContract crmContract)
    {
        List<CrmContract> list = crmContractService.selectCrmContractList(crmContract);
        ExcelUtil<CrmContract> util = new ExcelUtil<CrmContract>(CrmContract.class);
        util.exportExcel(response, list, "合同数据数据");
    }

    /**
     * 获取合同数据详细信息
     */
//    @PreAuthorize("@ss.hasPermi('crm:contract:query')")
    @GetMapping(value = "/{contractId}")
    public AjaxResult getInfo(@PathVariable("contractId") String contractId)
    {
        return success(crmContractService.selectCrmContractByContractId(contractId));
    }

    /**
     * 新增合同数据
     */
//    @PreAuthorize("@ss.hasPermi('crm:contract:add')")
    @Log(title = "合同数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmContract crmContract)
    {
        return toAjax(crmContractService.insertCrmContract(crmContract));
    }

    /**
     * 修改合同数据
     */
//    @PreAuthorize("@ss.hasPermi('crm:contract:edit')")
    @Log(title = "合同数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmContract crmContract)
    {
        return toAjax(crmContractService.updateCrmContract(crmContract));
    }

    /**
     * 删除合同数据
     */
//    @PreAuthorize("@ss.hasPermi('crm:contract:remove')")
    @Log(title = "合同数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractIds}")
    public AjaxResult remove(@PathVariable String[] contractIds)
    {
        return toAjax(crmContractService.deleteCrmContractByContractIds(contractIds));
    }

    /**
     * 获取合同数据
     * @param crmContract
     * @return
     */
    @PostMapping("/getContractInfo")
    public AjaxResult getContractInfo(@RequestBody CrmContract crmContract){
        return AjaxResult.success(crmContractService.getContractInfo(crmContract));
    }


    /**
     * 审核
     *
     * @param crmContract
     * @return
     */
    @PostMapping("audit")
    public AjaxResult audit(@RequestBody CrmContract crmContract) {
        return AjaxResult.success(crmContractService.audit(crmContract));
    }

}
